﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects.DataClasses;

namespace GeckoPhotos.Repository
{
    public interface IRepository<TKey, TModel>
        where TKey : IComparable
        where TModel : EntityObject
    {
        /// <summary>
        /// Returns all items.
        /// </summary>
        /// <returns></returns>
        IQueryable<TModel> All();

        /// <summary>
        /// Returns only items matching <paramref name="query"/>.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        IQueryable<TModel> Where(Func<TModel, bool> query);

        /// <summary>
        /// Returns the single result matching <paramref name="query"/>; if not exactly 
        /// one result found, throws an <seealso cref="InvalidOperationException"/>.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        TModel Single(Func<TModel, bool> query);

        /// <summary>
        /// Adds an item.
        /// </summary>
        /// <param name="entity"></param>
        void Insert(TModel entity);

        /// <summary>
        /// Updates an item.
        /// </summary>
        /// <param name="entity"></param>
        void Update(TModel entity);

        /// <summary>
        /// Removes an item.
        /// </summary>
        /// <param name="entity"></param>
        void Remove(TModel entity);
    }

}
